// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
const Clutter = imports.gi.Clutter;
+const Gio = imports.gi.Gio;
const Lang = imports.lang;
const Signals = imports.signals;
const St = imports.gi.St;
this._initButtons();
- let spinnerIcon = global.datadir + '/theme/process-working.svg';
+ let spinnerIcon = Gio.File.new_for_path(global.datadir + '/theme/process-working.svg');
this._spinner = new Animation.AnimatedIcon(spinnerIcon, DEFAULT_BUTTON_WELL_ICON_SIZE);
this._spinner.actor.opacity = 0;
this._spinner.actor.show();
}
},
- _updateLogoTexture: function(cache, uri) {
- if (this._logoFileUri != uri)
+ _updateLogoTexture: function(cache, file) {
+ if (!this._logoFile.equal(file))
return;
this._logoBin.destroy_all_children();
- if (this._logoFileUri) {
+ if (this._logoFile) {
let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
- this._logoBin.add_child(this._textureCache.load_uri_async(this._logoFileUri,
- -1, _LOGO_ICON_HEIGHT,
- scaleFactor));
+ this._logoBin.add_child(this._textureCache.load_file_async(this._logoFile,
+ -1, _LOGO_ICON_HEIGHT,
+ scaleFactor));
}
},
_updateLogo: function() {
let path = this._settings.get_string(GdmUtil.LOGO_KEY);
- this._logoFileUri = path ? Gio.file_new_for_path(path).get_uri() : null;
- this._updateLogoTexture(this._textureCache, this._logoFileUri);
+ this._logoFile = path ? Gio.file_new_for_path(path) : null;
+ this._updateLogoTexture(this._textureCache, this._logoFile);
},
_onPrompted: function() {
const Animation = new Lang.Class({
Name: 'Animation',
- _init: function(filename, width, height, speed) {
+ _init: function(file, width, height, speed) {
this.actor = new St.Bin();
this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
this._speed = speed;
this._frame = 0;
let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
- this._animations = St.TextureCache.get_default().load_sliced_image (filename, width, height, scaleFactor,
+ this._animations = St.TextureCache.get_default().load_sliced_image (file, width, height, scaleFactor,
Lang.bind(this, this._animationsLoaded));
this.actor.set_child(this._animations);
},
Name: 'AnimatedIcon',
Extends: Animation,
- _init: function(filename, size) {
- this.parent(filename, size, size, ANIMATED_ICON_UPDATE_TIMEOUT);
+ _init: function(file, size) {
+ this.parent(file, size, size, ANIMATED_ICON_UPDATE_TIMEOUT);
}
});
let file = contact.get_avatar_file();
if (file) {
- let uri = file.get_uri();
let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
- iconBox.child = textureCache.load_uri_async(uri, iconBox._size, iconBox._size, scaleFactor);
+ iconBox.child = textureCache.load_file_async(file, iconBox._size, iconBox._size, scaleFactor);
}
else {
iconBox.child = new St.Icon({ icon_name: 'avatar-default',
},
placeSpinner: function(layoutInfo) {
- let spinnerIcon = global.datadir + '/theme/process-working.svg';
+ let spinnerIcon = Gio.File.new_for_path(global.datadir + '/theme/process-working.svg');
this._workSpinner = new Animation.AnimatedIcon(spinnerIcon, WORK_SPINNER_ICON_SIZE);
this._workSpinner.actor.opacity = 0;
this._workSpinner.actor.show();
_onStyleChanged: function(actor) {
let node = actor.get_theme_node();
let [success, icon] = node.lookup_url('spinner-image', false);
- if (!success || this._spinnerIcon == icon)
+ if (!success || (this._spinnerIcon && this._spinnerIcon.equal(icon)))
return;
this._spinnerIcon = icon;
this._spinner = new Animation.AnimatedIcon(this._spinnerIcon, PANEL_ICON_SIZE);
x_align: Clutter.ActorAlign.CENTER,
y_align: Clutter.ActorAlign.CENTER });
- this._noNetworksSpinner = new Animation.AnimatedIcon(global.datadir + '/theme/process-working.svg', 24, 24);
+ let file = Gio.File.new_for_path(global.datadir + '/theme/process-working.svg');
+ this._noNetworksSpinner = new Animation.AnimatedIcon(file, 24, 24);
this._noNetworksBox.add_actor(this._noNetworksSpinner.actor);
this._noNetworksBox.add_actor(new St.Label({ style_class: 'no-networks-label',
text: _("No Networks") }));
struct _StBorderImage {
GObject parent;
- char *filename;
+ GFile *file;
int border_top;
int border_right;
int border_bottom;
{
StBorderImage *image = ST_BORDER_IMAGE (object);
- g_free (image->filename);
+ g_object_unref (image->file);
G_OBJECT_CLASS (st_border_image_parent_class)->finalize (object);
}
}
StBorderImage *
-st_border_image_new (const char *filename,
- int border_top,
- int border_right,
- int border_bottom,
- int border_left,
- int scale_factor)
+st_border_image_new (GFile *file,
+ int border_top,
+ int border_right,
+ int border_bottom,
+ int border_left,
+ int scale_factor)
{
StBorderImage *image;
image = g_object_new (ST_TYPE_BORDER_IMAGE, NULL);
- image->filename = g_strdup (filename);
+ image->file = g_object_ref (file);
image->border_top = border_top;
image->border_right = border_right;
image->border_bottom = border_bottom;
return image;
}
-const char *
-st_border_image_get_filename (StBorderImage *image)
+/**
+ * st_border_image_get_file:
+ * @image: a #StBorder_Image
+ *
+ * Returns: (transfer none): the #GFile for the #StBorder_Image
+ */
+GFile *
+st_border_image_get_file (StBorderImage *image)
{
g_return_val_if_fail (ST_IS_BORDER_IMAGE (image), NULL);
- return image->filename;
+ return image->file;
}
void
image->border_right == other->border_right &&
image->border_bottom == other->border_bottom &&
image->border_left == other->border_left &&
- strcmp (image->filename, other->filename) == 0);
+ g_file_equal (image->file, other->file));
}
#define __ST_BORDER_IMAGE_H__
#include <glib-object.h>
+#include <gio/gio.h>
G_BEGIN_DECLS
GType st_border_image_get_type (void) G_GNUC_CONST;
-StBorderImage *st_border_image_new (const char *filename,
+StBorderImage *st_border_image_new (GFile *file,
int border_top,
int border_right,
int border_bottom,
int border_left,
int scale_factor);
-const char *st_border_image_get_filename (StBorderImage *image);
+GFile *st_border_image_get_file (StBorderImage *image);
void st_border_image_get_borders (StBorderImage *image,
int *border_top,
int *border_right,
#include <glib.h>
#define CACHE_PREFIX_ICON "icon:"
-#define CACHE_PREFIX_URI "uri:"
-#define CACHE_PREFIX_URI_FOR_CAIRO "uri-for-cairo:"
+#define CACHE_PREFIX_FILE "file:"
+#define CACHE_PREFIX_FILE_FOR_CAIRO "file-for-cairo:"
struct _StTextureCachePrivate
{
G_SIGNAL_RUN_LAST,
0, /* no default handler slot */
NULL, NULL, NULL,
- G_TYPE_NONE, 1, G_TYPE_STRING);
+ G_TYPE_NONE, 1, G_TYPE_FILE);
}
/* Evicts all cached textures for named icons */
g_free, cogl_object_unref);
self->priv->outstanding_requests = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, NULL);
- self->priv->file_monitors = g_hash_table_new_full (g_str_hash, g_str_equal,
+ self->priv->file_monitors = g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal,
g_object_unref, g_object_unref);
}
GtkIconInfo *icon_info;
StIconColors *colors;
- char *uri;
+ GFile *file;
} AsyncTextureLoadData;
static void
if (data->colors)
st_icon_colors_unref (data->colors);
}
- else if (data->uri)
- g_free (data->uri);
+ else if (data->file)
+ g_object_unref (data->file);
if (data->key)
g_free (data->key);
}
static GdkPixbuf *
-impl_load_pixbuf_file (const char *uri,
+impl_load_pixbuf_file (GFile *file,
int available_width,
int available_height,
int scale,
GError **error)
{
GdkPixbuf *pixbuf = NULL;
- GFile *file;
char *contents = NULL;
gsize size;
- file = g_file_new_for_uri (uri);
if (g_file_load_contents (file, NULL, &contents, &size, NULL, error))
{
pixbuf = impl_load_pixbuf_data ((const guchar *) contents, size,
error);
}
- g_object_unref (file);
g_free (contents);
return pixbuf;
data = g_async_result_get_user_data (G_ASYNC_RESULT (result));
g_assert (data != NULL);
- g_assert (data->uri != NULL);
+ g_assert (data->file != NULL);
- pixbuf = impl_load_pixbuf_file (data->uri, data->width, data->height, data->scale, &error);
+ pixbuf = impl_load_pixbuf_file (data->file, data->width, data->height, data->scale, &error);
if (error != NULL)
{
load_texture_async (StTextureCache *cache,
AsyncTextureLoadData *data)
{
- if (data->uri)
+ if (data->file)
{
GSimpleAsyncResult *result;
result = g_simple_async_result_new (G_OBJECT (cache), on_pixbuf_loaded, data, load_texture_async);
gpointer user_data)
{
StTextureCache *cache = user_data;
- char *uri, *key;
+ char *key;
+ guint file_hash;
if (event_type != G_FILE_MONITOR_EVENT_CHANGED)
return;
- uri = g_file_get_uri (file);
+ file_hash = g_file_hash (file);
- key = g_strconcat (CACHE_PREFIX_URI, uri, NULL);
+ key = g_strdup_printf (CACHE_PREFIX_FILE "%u", file_hash);
g_hash_table_remove (cache->priv->keyed_cache, key);
g_free (key);
- key = g_strconcat (CACHE_PREFIX_URI_FOR_CAIRO, uri, NULL);
+ key = g_strdup_printf (CACHE_PREFIX_FILE_FOR_CAIRO "%u", file_hash);
g_hash_table_remove (cache->priv->keyed_cache, key);
g_free (key);
- g_signal_emit (cache, signals[TEXTURE_FILE_CHANGED], 0, uri);
-
- g_free (uri);
+ g_signal_emit (cache, signals[TEXTURE_FILE_CHANGED], 0, file);
}
static void
-ensure_monitor_for_uri (StTextureCache *cache,
- const gchar *uri)
+ensure_monitor_for_file (StTextureCache *cache,
+ GFile *file)
{
StTextureCachePrivate *priv = cache->priv;
- GFile *file = g_file_new_for_uri (uri);
- if (g_hash_table_lookup (priv->file_monitors, uri) == NULL)
+ if (g_hash_table_lookup (priv->file_monitors, file) == NULL)
{
GFileMonitor *monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE,
NULL, NULL);
g_signal_connect (monitor, "changed",
G_CALLBACK (file_changed_cb), cache);
- g_hash_table_insert (priv->file_monitors, g_strdup (uri), monitor);
+ g_hash_table_insert (priv->file_monitors, g_object_ref (file), monitor);
}
- g_object_unref (file);
}
typedef struct {
- gchar *path;
+ GFile *gfile;
gint grid_width, grid_height;
gint scale_factor;
ClutterActor *actor;
on_data_destroy (gpointer data)
{
AsyncImageData *d = (AsyncImageData *)data;
- g_free (d->path);
+ g_object_unref (d->gfile);
g_object_unref (d->actor);
g_free (d);
}
loader = gdk_pixbuf_loader_new ();
g_signal_connect (loader, "size-prepared", G_CALLBACK (on_loader_size_prepared), data);
- if (!g_file_get_contents (data->path, &buffer, &length, NULL))
+ if (!g_file_load_contents (data->gfile, NULL, &buffer, &length, NULL, NULL))
goto out;
if (!gdk_pixbuf_loader_write (loader, (const guchar *) buffer, length, NULL))
/**
* st_texture_cache_load_sliced_image:
* @cache: A #StTextureCache
- * @path: Path to a filename
+ * @file: A #GFile
* @grid_width: Width in pixels
* @grid_height: Height in pixels
* @scale: Scale factor of the display
*/
ClutterActor *
st_texture_cache_load_sliced_image (StTextureCache *cache,
- const gchar *path,
+ GFile *file,
gint grid_width,
gint grid_height,
gint scale,
data->grid_width = grid_width;
data->grid_height = grid_height;
data->scale_factor = scale;
- data->path = g_strdup (path);
+ data->gfile = g_object_ref (file);
data->actor = actor;
data->load_callback = load_callback;
data->load_callback_data = user_data;
}
/**
- * st_texture_cache_load_uri_async:
+ * st_texture_cache_load_file_async:
* @cache: The texture cache instance
- * @uri: uri of the image file from which to create a pixbuf
+ * @file: a #GFile of the image file from which to create a pixbuf
* @available_width: available width for the image, can be -1 if not limited
* @available_height: available height for the image, can be -1 if not limited
* @scale: scale factor of the display
* Return value: (transfer none): A new #ClutterActor with no image loaded initially.
*/
ClutterActor *
-st_texture_cache_load_uri_async (StTextureCache *cache,
- const gchar *uri,
- int available_width,
- int available_height,
- int scale)
+st_texture_cache_load_file_async (StTextureCache *cache,
+ GFile *file,
+ int available_width,
+ int available_height,
+ int scale)
{
ClutterActor *texture;
AsyncTextureLoadData *request;
StTextureCachePolicy policy;
gchar *key;
- key = g_strconcat (CACHE_PREFIX_URI, uri, NULL);
+ key = g_strdup_printf (CACHE_PREFIX_FILE "%u", g_file_hash (file));
policy = ST_TEXTURE_CACHE_POLICY_NONE; /* XXX */
request->cache = cache;
/* Transfer ownership of key */
request->key = key;
- request->uri = g_strdup (uri);
+ request->file = g_object_ref (file);
request->policy = policy;
request->width = available_width;
request->height = available_height;
load_texture_async (cache, request);
}
- ensure_monitor_for_uri (cache, uri);
+ ensure_monitor_for_file (cache, file);
return CLUTTER_ACTOR (texture);
}
static CoglTexture *
-st_texture_cache_load_uri_sync_to_cogl_texture (StTextureCache *cache,
- StTextureCachePolicy policy,
- const gchar *uri,
- int available_width,
- int available_height,
- int scale,
- GError **error)
+st_texture_cache_load_file_sync_to_cogl_texture (StTextureCache *cache,
+ StTextureCachePolicy policy,
+ GFile *file,
+ int available_width,
+ int available_height,
+ int scale,
+ GError **error)
{
CoglTexture *texdata;
GdkPixbuf *pixbuf;
char *key;
- key = g_strconcat (CACHE_PREFIX_URI, uri, NULL);
+ key = g_strdup_printf (CACHE_PREFIX_FILE "%u", g_file_hash (file));
texdata = g_hash_table_lookup (cache->priv->keyed_cache, key);
if (texdata == NULL)
{
- pixbuf = impl_load_pixbuf_file (uri, available_width, available_height, scale, error);
+ pixbuf = impl_load_pixbuf_file (file, available_width, available_height, scale, error);
if (!pixbuf)
goto out;
else
cogl_object_ref (texdata);
- ensure_monitor_for_uri (cache, uri);
+ ensure_monitor_for_file (cache, file);
out:
g_free (key);
}
static cairo_surface_t *
-st_texture_cache_load_uri_sync_to_cairo_surface (StTextureCache *cache,
- StTextureCachePolicy policy,
- const gchar *uri,
- int available_width,
- int available_height,
- int scale,
- GError **error)
+st_texture_cache_load_file_sync_to_cairo_surface (StTextureCache *cache,
+ StTextureCachePolicy policy,
+ GFile *file,
+ int available_width,
+ int available_height,
+ int scale,
+ GError **error)
{
cairo_surface_t *surface;
GdkPixbuf *pixbuf;
char *key;
- key = g_strconcat (CACHE_PREFIX_URI_FOR_CAIRO, uri, NULL);
+ key = g_strdup_printf (CACHE_PREFIX_FILE_FOR_CAIRO "%u", g_file_hash (file));
surface = g_hash_table_lookup (cache->priv->keyed_cache, key);
if (surface == NULL)
{
- pixbuf = impl_load_pixbuf_file (uri, available_width, available_height, scale, error);
+ pixbuf = impl_load_pixbuf_file (file, available_width, available_height, scale, error);
if (!pixbuf)
goto out;
else
cairo_surface_reference (surface);
- ensure_monitor_for_uri (cache, uri);
+ ensure_monitor_for_file (cache, file);
out:
g_free (key);
/**
* st_texture_cache_load_file_to_cogl_texture: (skip)
* @cache: A #StTextureCache
- * @file_path: Path to a file in supported image format
+ * @file: A #GFile in supported image format
* @scale: Scale factor of the display
*
* This function synchronously loads the given file path
*/
CoglTexture *
st_texture_cache_load_file_to_cogl_texture (StTextureCache *cache,
- const gchar *file_path,
+ GFile *file,
gint scale)
{
CoglTexture *texture;
- GFile *file;
- char *uri;
GError *error = NULL;
- file = g_file_new_for_path (file_path);
- uri = g_file_get_uri (file);
-
- texture = st_texture_cache_load_uri_sync_to_cogl_texture (cache, ST_TEXTURE_CACHE_POLICY_FOREVER,
- uri, -1, -1, scale, &error);
- g_object_unref (file);
- g_free (uri);
+ texture = st_texture_cache_load_file_sync_to_cogl_texture (cache, ST_TEXTURE_CACHE_POLICY_FOREVER,
+ file, -1, -1, scale, &error);
if (texture == NULL)
{
- g_warning ("Failed to load %s: %s", file_path, error->message);
+ char *uri = g_file_get_uri (file);
+ g_warning ("Failed to load %s: %s", uri, error->message);
g_clear_error (&error);
- return NULL;
+ g_free (uri);
}
+
return texture;
}
/**
* st_texture_cache_load_file_to_cairo_surface:
* @cache: A #StTextureCache
- * @file_path: Path to a file in supported image format
+ * @file: A #GFile in supported image format
* @scale: Scale factor of the display
*
* This function synchronously loads the given file path
*/
cairo_surface_t *
st_texture_cache_load_file_to_cairo_surface (StTextureCache *cache,
- const gchar *file_path,
+ GFile *file,
gint scale)
{
cairo_surface_t *surface;
- GFile *file;
- char *uri;
GError *error = NULL;
- file = g_file_new_for_path (file_path);
- uri = g_file_get_uri (file);
-
- surface = st_texture_cache_load_uri_sync_to_cairo_surface (cache, ST_TEXTURE_CACHE_POLICY_FOREVER,
- uri, -1, -1, scale, &error);
- g_object_unref (file);
- g_free (uri);
+ surface = st_texture_cache_load_file_sync_to_cairo_surface (cache, ST_TEXTURE_CACHE_POLICY_FOREVER,
+ file, -1, -1, scale, &error);
if (surface == NULL)
{
- g_warning ("Failed to load %s: %s", file_path, error->message);
+ char *uri = g_file_get_uri (file);
+ g_warning ("Failed to load %s: %s", uri, error->message);
g_clear_error (&error);
- return NULL;
+ g_free (uri);
}
+
return surface;
}
ClutterActor *
st_texture_cache_load_sliced_image (StTextureCache *cache,
- const gchar *path,
+ GFile *file,
gint grid_width,
gint grid_height,
gint scale,
gint size,
gint scale);
-ClutterActor *st_texture_cache_load_uri_async (StTextureCache *cache,
- const gchar *uri,
- int available_width,
- int available_height,
- int scale);
+ClutterActor *st_texture_cache_load_file_async (StTextureCache *cache,
+ GFile *file,
+ int available_width,
+ int available_height,
+ int scale);
CoglTexture *st_texture_cache_load_file_to_cogl_texture (StTextureCache *cache,
- const gchar *file_path,
+ GFile *file,
gint scale);
cairo_surface_t *st_texture_cache_load_file_to_cairo_surface (StTextureCache *cache,
- const gchar *file_path,
+ GFile *file,
gint scale);
/**
cairo_pattern_t *pattern;
cairo_content_t content;
cairo_matrix_t matrix;
- const char *file;
+ GFile *file;
StTextureCache *texture_cache;
}
else
{
- const char *background_image;
+ GFile *background_image;
background_image = st_theme_node_get_background_image (node);
if (border_image == NULL)
goto out;
- const char *filename;
- filename = st_border_image_get_filename (border_image);
+ GFile *file;
+ file = st_border_image_get_file (border_image);
int scale_factor;
g_object_get (node->context, "scale-factor", &scale_factor, NULL);
node->border_slices_texture = st_texture_cache_load_file_to_cogl_texture (st_texture_cache_get_default (),
- filename, scale_factor);
+ file, scale_factor);
if (node->border_slices_texture == COGL_INVALID_HANDLE)
goto out;
{
if (node->background_texture == COGL_INVALID_HANDLE)
{
- const char *background_image;
+ GFile *background_image;
StShadow *background_image_shadow_spec;
background_image = st_theme_node_get_background_image (node);
int transition_duration;
- char *background_image;
+ GFile *background_image;
StBorderImage *border_image;
StShadow *box_shadow;
StShadow *background_image_shadow;
}
if (node->background_image)
- g_free (node->background_image);
+ {
+ g_object_unref (node->background_image);
+ node->background_image = NULL;
+ }
if (node->background_texture != COGL_INVALID_HANDLE)
cogl_handle_unref (node->background_texture);
* parent's parent, and so forth. Note that if the property has a
* value of 'inherit' it will be inherited even if %FALSE is passed
* in for @inherit; this only affects the default behavior for inheritance.
- * @value: (out): location to store the newly allocated value that was
+ * @file: (out) (transfer full): location to store the newly allocated value that was
* determined. If the property is not found, the value in this location
* will not be changed.
*
st_theme_node_lookup_url (StThemeNode *node,
const char *property_name,
gboolean inherit,
- char **value)
+ GFile **file)
{
gboolean result = FALSE;
int i;
{
CRTerm *term = decl->value;
CRStyleSheet *base_stylesheet;
- GFile *file;
if (term->type != TERM_URI && term->type != TERM_STRING)
continue;
else
base_stylesheet = NULL;
- file = _st_theme_resolve_url (node->theme,
- base_stylesheet,
- decl->value->content.str->stryng->str);
- *value = g_file_get_path (file);
- g_object_unref (file);
+ *file = _st_theme_resolve_url (node->theme,
+ base_stylesheet,
+ decl->value->content.str->stryng->str);
result = TRUE;
break;
}
}
if (!result && inherit && node->parent_node)
- result = st_theme_node_lookup_url (node->parent_node, property_name, inherit, value);
+ result = st_theme_node_lookup_url (node->parent_node, property_name, inherit, file);
return result;
}
-/*
+/**
* st_theme_node_get_url:
* @node: a #StThemeNode
* @property_name: The name of the string property
* and lets you handle the case where the theme does not specify the
* indicated value.
*
- * Return value: the newly allocated value if found.
+ * Returns: (transfer full): the newly allocated value if found.
* If @property_name is not found, a warning will be logged and %NULL
* will be returned.
*/
-char *
+GFile *
st_theme_node_get_url (StThemeNode *node,
const char *property_name)
{
- char *value;
+ GFile *file;
- if (st_theme_node_lookup_url (node, property_name, FALSE, &value))
- return value;
+ if (st_theme_node_lookup_url (node, property_name, FALSE, &file))
+ return file;
else
{
g_warning ("Did not find string property '%s'", property_name);
CRTerm *term;
/* background: property sets all terms to specified or default values */
node->background_color = TRANSPARENT_COLOR;
- g_free (node->background_image);
- node->background_image = NULL;
+ g_clear_object (&node->background_image);
node->background_position_set = FALSE;
node->background_size = ST_BACKGROUND_SIZE_AUTO;
if (node->parent_node)
{
st_theme_node_get_background_color (node->parent_node, &node->background_color);
- node->background_image = g_strdup (st_theme_node_get_background_image (node->parent_node));
+ node->background_image = g_object_ref (st_theme_node_get_background_image (node->parent_node));
}
}
else if (term_is_none (term))
base_stylesheet,
term->content.str->stryng->str);
- node->background_image = g_file_get_path (file);
- g_object_unref (file);
+ node->background_image = file;
}
}
}
if (decl->value->type == TERM_URI)
{
CRStyleSheet *base_stylesheet;
- GFile *file;
if (decl->parent_statement != NULL)
base_stylesheet = decl->parent_statement->parent_sheet;
else
base_stylesheet = NULL;
- g_free (node->background_image);
- file = _st_theme_resolve_url (node->theme,
- base_stylesheet,
- decl->value->content.str->stryng->str);
-
- node->background_image = g_file_get_path (file);
- g_object_unref (file);
+ g_clear_object (&node->background_image);
+ node->background_image = _st_theme_resolve_url (node->theme,
+ base_stylesheet,
+ decl->value->content.str->stryng->str);
}
else if (term_is_inherit (decl->value))
{
- g_free (node->background_image);
- node->background_image = g_strdup (st_theme_node_get_background_image (node->parent_node));
+ g_clear_object (&node->background_image);
+ node->background_image = g_object_ref (st_theme_node_get_background_image (node->parent_node));
}
else if (term_is_none (decl->value))
{
- g_free (node->background_image);
- node->background_image = NULL;
+ g_clear_object (&node->background_image);
}
}
else if (strcmp (property_name, "-gradient-direction") == 0)
*color = node->background_color;
}
-const char *
+/**
+ * st_theme_node_get_background_image:
+ * @node: a #StThemeNode
+ *
+ * Returns: (transfer none): @node's background image.
+ */
+GFile *
st_theme_node_get_background_image (StThemeNode *node)
{
g_return_val_if_fail (ST_IS_THEME_NODE (node), NULL);
int border_left;
GFile *file;
- char *filename;
/* Support border-image: none; to suppress a previously specified border image */
if (term_is_none (term))
base_stylesheet = NULL;
file = _st_theme_resolve_url (node->theme, base_stylesheet, url);
- filename = g_file_get_path (file);
- g_object_unref (file);
- if (filename == NULL)
+ if (file == NULL)
goto next_property;
- node->border_image = st_border_image_new (filename,
+ node->border_image = st_border_image_new (file,
border_top, border_right, border_bottom, border_left,
scale_factor);
- g_free (filename);
+ g_object_unref (file);
return node->border_image;
}
!clutter_color_equal (&node->background_gradient_end, &other->background_gradient_end))
return FALSE;
- if (g_strcmp0 (node->background_image, other->background_image) != 0)
+ if ((node->background_image != NULL) &&
+ (other->background_image != NULL) &&
+ !g_file_equal (node->background_image, other->background_image))
return FALSE;
_st_theme_node_ensure_geometry (node);
gboolean st_theme_node_lookup_url (StThemeNode *node,
const char *property_name,
gboolean inherit,
- char **value);
+ GFile **file);
/* Easier-to-use variants of the above, for application-level use */
void st_theme_node_get_color (StThemeNode *node,
const char *property_name);
StShadow *st_theme_node_get_shadow (StThemeNode *node,
const char *property_name);
-char *st_theme_node_get_url (StThemeNode *node,
+GFile *st_theme_node_get_url (StThemeNode *node,
const char *property_name);
/* Specific getters for particular properties: cached
ClutterColor *start,
ClutterColor *end);
-const char *st_theme_node_get_background_image (StThemeNode *node);
+GFile *st_theme_node_get_background_image (StThemeNode *node);
int st_theme_node_get_border_width (StThemeNode *node,
StSide side);
return props;
}
-/* Resolve an url from an url() reference in a stylesheet into an absolute
- * local filename, if possible. The resolution here is distinctly lame and
+/* Resolve an url from an url() reference in a stylesheet into a GFile,
+ * if possible. The resolution here is distinctly lame and
* will fail on many examples.
*/
GFile *
static void
st_widget_texture_cache_changed (StTextureCache *cache,
- const char *uri,
+ GFile *file,
gpointer user_data)
{
StWidget *actor = ST_WIDGET (user_data);
StThemeNode *node = actor->priv->theme_node;
- char *path;
gboolean changed = FALSE;
+ GFile *theme_file;
if (node == NULL)
return;
- path = g_filename_from_uri (uri, NULL, NULL);
-
- if (g_strcmp0 (st_theme_node_get_background_image (node), path) == 0)
+ theme_file = st_theme_node_get_background_image (node);
+ if ((theme_file != NULL) && g_file_equal (theme_file, file))
{
st_theme_node_invalidate_background_image (node);
changed = TRUE;
}
- if (g_strcmp0 (st_border_image_get_filename (st_theme_node_get_border_image (node)), path) == 0)
+ theme_file = st_border_image_get_file (st_theme_node_get_border_image (node));
+ if ((theme_file != NULL) && g_file_equal (theme_file, file))
{
st_theme_node_invalidate_border_image (node);
changed = TRUE;
if (CLUTTER_ACTOR_IS_MAPPED (CLUTTER_ACTOR (actor)))
clutter_actor_queue_redraw (CLUTTER_ACTOR (actor));
}
-
- g_free (path);
}
static void
const char *node_description,
const char *expected)
{
- const char *value = st_theme_node_get_background_image (node);
- if (expected == NULL)
- expected = "(null)";
- if (value == NULL)
- value = "(null)";
+ GFile *value = st_theme_node_get_background_image (node);
+ GFile *expected_file;
- if (strcmp (expected, value) != 0)
+ if (expected != NULL && value != NULL)
{
- g_print ("%s: %s.background-image: expected: %s, got: %s\n",
- test, node_description, expected, value);
- fail = TRUE;
+ expected_file = g_file_new_for_path (expected);
+
+ if (!g_file_equal (expected_file, value))
+ {
+ char *uri = g_file_get_uri (expected_file);
+ g_print ("%s: %s.background-image: expected: %s, got: %s\n",
+ test, node_description, expected, uri);
+ fail = TRUE;
+ g_free (uri);
+ }
}
}